﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Core.Web;

using $prjsn$.Common;

namespace $safeprojectname$.Controls
{
    public abstract class ActionsBlock : RazorControl<IViewModel>
    {
        protected static readonly IList<string> KnownQuickActions = new List<string>
        {
            Str.Actions.New,
            Str.Actions.Find,
            Str.Actions.List,
            Str.Business.Home.Actions.SelectLanguage,
            Str.Business.Services.SelectRole,
            Str.Actions.ExportImport.ListToExcel,
            Str.Actions.ExportImport.Import,
            Str.Business.Home.Actions.Refresh,
            Str.Business.Services.Upload,

        };
        protected static readonly IList<string> SpecialActions = new List<string>
        {
            Str.Actions.MoveNext,
            Str.Actions.MovePrev,
        };

        protected virtual string CreateText(IActionItem action)
        {
            return action.TextLocalized.IsNotEmpty()
                 ? action.TextLocalized
                 : GetLocalized(action.Text);
        }

        protected virtual string CreateTitle(IActionItem action)
        {
            var title = action.TitleLocalized.IsNotEmpty()
                 ? action.TitleLocalized
                 : (action.Title.Is() ? GetLocalized(action.Title) : string.Empty);
            if (title.Equals(string.Empty))
            {
                title = CreateText(action);
            }
            return title + GetTitleAccessKey(action.ActionName);
        }
        protected virtual string GetTitleAccessKey(string actionName)
        {
            switch (actionName)
            {
                case Str.Actions.New:
                    return " (Shift + Alt + N)";
                case Str.Actions.ExportImport.ListToExcel:
                    return " (Shift + Alt + E)";
                case Str.Actions.List:
                    return " (Shift + Alt + L)";
                case Str.Actions.Find:
                    return " (Shift + Alt + F)";
            }
            return string.Empty;
        }

        protected virtual string CreateHref(IActionItem action)
        {
            return action.Href.IsNotEmpty()
                 ? action.Href
                 : Url.Action(action.ActionName, action.ControllerName, action.RouteValues);
        }

        protected virtual string CreateAccesskey(IActionItem action)
        {
            switch (action.ActionName)
            {
                case Str.Actions.New: return "n";
                case Str.Actions.Find: return "f";
                case Str.Actions.List: return "l";
                case Str.Business.Home.Actions.SelectLanguage: return "l";
                case Str.Business.Services.SelectRole: return "r";
                case Str.Actions.ExportImport.ListToExcel: return "e";
            }
            return null;
        }

        protected virtual string Assure(IActionItem action)
        {
            var model = Model as IEntityModel<IPersistentObject, IFilter>;
            if (model.IsNull())
            {
                return null;
            }
            if (action.ActionName.IsEqual(Str.Actions.ExportImport.ListToExcel))
            {
                return GetLocalized(Str.Common.Excel.DoExportToExcelTotalRows)
                    .FormatWith(model.Filter.TotalRows);
            }
            return null;
        }
    }
}